#include<bits/stdc++.h>
using namespace std;
using ll=int;
ll p; 
vector<int> f[448];
ll calc(ll x,ll y) {
	return f[y][x];
}
void sol() {
	ll n;
	cin>>n;
	ll ans=0;
	for(int i=1;i*i<=n;i++)
		if(!((n-i*i)&1))
			ans+=calc((n-i*i)/2,i),ans%=p;
	cout<<ans<<'\n';
}
int main(){
	freopen("moon.in","r",stdin);
	freopen("moon.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	ll t;
	cin>>t>>p;
	for(int j=0;j<=200000;j++) 
		f[0].push_back(0);
	f[0][0]=1;
	for(int i=1;i<=448;i++) {
		for(int j=0;j<=(200000-i*i)/2;j++)
			f[i].push_back(f[i-1][j]);
		for(int j=0;j<=(200000-i*i)/2;j++)
			f[i][j]=f[i-1][j];
		for(int j=i;j<=(200000-i*i)/2;j++) 
			f[i][j]=(f[i][j]+f[i][j-i])%p;
	}
	while(t--)
		sol(); 
	return 0;
}



